﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DungDungShit
{
    public class IntVector2
    {
        public int X, Y;

        public IntVector2() : this(0, 0) { }
        public IntVector2(int X, int Y)
        {
            this.X = X;
            this.Y = Y;
        }
        //public IntVector2(IntVector2 v) : this(v.X, v.Y) { }
        public IntVector2(Vector2 v) : this(Convert.ToInt32(v.X), Convert.ToInt32(v.Y)) { }

        public static implicit operator Vector2(IntVector2 v)
        {
            return new Vector2(v.X, v.Y);
        }
        public static IntVector2 operator +(IntVector2 v1, IntVector2 v2)
        {
            return new IntVector2(v1.X + v2.X, v1.Y + v2.Y);
        }
        public static IntVector2 operator *(IntVector2 v, int k)
        {
            return k * v;
        }
        public static IntVector2 operator *(int k, IntVector2 v)
        {
            return new IntVector2(k * v.X, k * v.Y);
        }
        public static bool operator ==(IntVector2 v1, IntVector2 v2)
        {
            // If both are null, or both are same instance, return true.
            if (System.Object.ReferenceEquals(v1, v2))
            {
                return true;
            }

            // If one is null, but not both, return false.
            if (((object)v1 == null) || ((object)v2 == null))
            {
                return false;
            }

            return v1.X == v2.X && v1.Y == v2.Y;
        }
        public static bool operator !=(IntVector2 v1, IntVector2 v2)
        {
            return !(v1 == v2);
        }
        public override bool Equals(object obj)
        {
            IntVector2 v = obj as IntVector2;
            if (v != null) return this == v;
            else return false;
        }
        public override int GetHashCode()
        {
            return (this.X ^ this.Y) + 0x789ABC;
        }
        public static IntVector2 Zero { get { return new IntVector2(); } }
        public static int SquaredDistance(IntVector2 v1, IntVector2 v2)
        {
            int x = v1.X - v2.X;
            int y = v1.Y - v2.Y;
            return x * x + y * y;
        }
        public static int DotProduct(IntVector2 v1, IntVector2 v2)
        {
            return v1.X * v2.X + v1.Y * v2.Y;
        }
        public override string ToString()
        {
            return "X:" + X + " Y:" + Y;
        }
    }

    class Direction : IntVector2
    {
        private Direction(int X, int Y)
        {
            if (Math.Abs(X) > Math.Abs(Y))
            {
                this.X = Math.Sign(X); this.Y = 0;
            }
            else
            {
                this.X = 0; this.Y = Math.Sign(Y);
            }
        }
        public Direction(IntVector2 v) : this(v.X, v.Y) { }

        public static readonly Direction None = new Direction(0, 0);
        public static readonly Direction Left = new Direction(-1, 0);
        public static readonly Direction Right = new Direction(1, 0);
        public static readonly Direction Up = new Direction(0, -1);
        public static readonly Direction Down = new Direction(0, 1);

        public override string ToString()
        {
            if (this == None) return "Direction.None";
            else if (this == Left) return "Direction.Left";
            else if (this == Right) return "Direction.Right";
            else if (this == Up) return "Direction.Up";
            else if (this == Down) return "Direction.Down";
            else return base.ToString();
        }
    }

    public class Util
    {
        public static Random Random = new Random();
    }
}
